import {
  craneControlConfig,
  lineMainConfig
} from '@/components/custom/homePage/homeCpt/myIndex/config';
import { N_cStph } from '@/types';
import { Action, Module, Mutation, VuexModule } from 'vuex-module-decorators';

@Module
export default class PLC extends VuexModule {
  // PLC状态
  plcStatus: boolean = true;

  // 槽位状态
  public tanks: N_cStph.TankConfig[] = [];

  // 行车控制状态
  public cranes: N_cStph.craneControlConfig[] = [];

  get PlcStatus(): any {
    return this.plcStatus;
  }

  get Tanks(): any {
    return this.tanks;
  }

  get Cranes(): any {
    return this.cranes;
  }

  @Mutation
  SET_PLCCONFIGS(status: boolean): any {
    this.plcStatus = status;
  }

  // 初始化状态
  @Mutation
  INIT_PLC_STATE(payload: {
    tanks: N_cStph.TankConfig[];
    cranes: N_cStph.craneControlConfig[];
  }): void {
    this.tanks = payload.tanks;
    this.cranes = payload.cranes;
  }

  // 更新槽位信息
  @Mutation
  UPDATE_SLOT_INFO(payload: N_cStph.TankConfig[]): void {
    this.tanks = payload;
  }

  // 更新行车信息
  @Mutation
  UPDATE_CAR_INFO(payload: N_cStph.craneControlConfig[]): void {
    this.cranes = payload;
  }

  // 初始化PLC数据
  @Action
  initPlcData(): void {
    this.context.commit('INIT_PLC_STATE', {
      tanks: lineMainConfig().tanks,
      cranes: craneControlConfig()
    });
  }
}
